package bo.zhao.action.singleton;

public class Engine {

	private static  Engine instance = null; 
	
	private String name=null;
	
	/**
	 * 获得单例, 低并发
	 * */
	public static Engine getInstance1() {
		if(instance==null) {
			instance=new Engine();
		}
		return instance;
	}
	
	
	/**
	 * 获得单例 , 稍高并发
	 * */
	public static Engine getInstance2() {
		if(instance==null) {
			synchronized (instance) {
				if (instance == null) {  
					instance=new Engine();
				}
			}
		}
		return instance;
	}
	
	
	
	protected static final  Engine instance3 = new Engine(); 
	
	/**
	 * 获得单例 , 高并发，启动时初始化
	 * */
	public static Engine getInstance3() {
		return instance3;
	}
	
	
	
	/**
	 * 构造函数
	 * */
	protected Engine() {
		this.name="eg-"+System.nanoTime();
		System.out.println("create engine "+name);
	}
	
	/**
	 * 运行
	 * */
	public void run() {
		System.out.println("running "+this.name+" ......");
	}
	
}
 
